//
//  setting_Date.m
//  01_kakin
//
//  Created by jon due on 12/04/09.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "setting_Date.h"

@implementation setting_Date


@synthesize dataLabel = _dataLabel;
@synthesize dPicker = _dPicker;


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    // picker
    
    NSDate *date = [ DefaultUril readDefaultsDate:key_AlermTime ];
    
    self.dataLabel.text = [ SADateUtil TimeToFormatString:date ];  
    [ self.dPicker setDate:date animated:YES ];
    [self.dPicker addTarget:self action:@selector(saveDatePicker:)forControlEvents:UIControlEventValueChanged];
    
    self.navigationItem.rightBarButtonItem =
    [[UIBarButtonItem alloc] initWithTitle:@"登録"
                                     style:UIBarButtonItemStylePlain
                                    target:self 
                                    action:@selector(DoneBtnAction:)];
    
}

-(void)viewWillAppear:(BOOL)animated{
    [ super viewWillAppear:animated ];
    
    self.navigationController.navigationBarHidden = NO;
    
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    
    _dataLabel = nil;
    _dPicker = nil;
    
}

-(void)dealloc{
    [ _dataLabel release ];
    [ _dPicker release ];
    [ super dealloc ];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

/* ============================================================================== */
#pragma mark - datePicker action
/* ============================================================================== */

-(void)saveDatePicker:(UIDatePicker*)p{
    
    self.dataLabel.text = [ SADateUtil TimeToFormatString:p.date ];
    
}

/* ============================================================================== */
#pragma mark - btn Action
/* ============================================================================== */

-(void)DoneBtnAction:(UIBarButtonItem*)btn{
    
    // アラーム時間とosに予約
    [ DefaultUril writeDefaultsDate:key_AlermTime : self.dPicker.date ];
    
    // 戻る
    [ (SANavigationController*)self.navigationController popViewControllerAnimated:NO ];
    
}

@end
